<?php


namespace App\Models\MainDB\Channel;


use Illuminate\Database\Eloquent\Model;
//渠道分期
class ChannelStage extends Model
{
    protected $table = 'ln_channel_stage'; //数据库内完整表名

    protected $primaryKey = 'id'; //主键名

    protected $fillable = [
        'id', //主键id
        'channel_id', //所属渠道id
        'name', //名称
        'promote_url_type', //推广链接类型：1：h5链接；2：渠道包
        'promote_url', //推广链接
        'bag_type', //包类型：1：安卓；2：ios；3：安卓ios二合一
        'bag_download_url', //包下载链接
        'remark', //备注
        'room_ids', //默认进房id
        'status', //状态：1：启用；0：禁用
    ];

    public $timestamps = false;

    //关联渠道分期数据（一对一）
    public function channel_stage_data()
    {
        return $this->hasOne('App\Models\MainDB\Channel\ChannelStageData', 'channel_stage_id', 'id');
    }

    //获取所有分期对应的渠道信息
    public function getAllStageChannelInfo()
    {
        $stages = app('model_channel_stage')->from('ln_channel_stage as cs')
            ->leftJoin('ln_channel as c', 'cs.channel_id', '=', 'c.id')
            ->select('cs.channel_id', 'c.name', 'cs.id')
            ->get()->toArray();
        return array_column($stages, null, 'id');
    }

    //查询所有渠道分期
    public function getChannelStageIdNameMap()
    {
        return $this->select('id', 'name')->pluck('name', 'id')->toArray();
    }
}